﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;


/// <summary>
/// 控制器，用来 “控制” 数据显示到界面上，指挥别人做事
/// </summary>
public class PlayerContoller
{

    /// <summary>
    /// 持有数据
    /// </summary>
    private PlayerModel model;
    /// <summary>
    /// 持有视图，界面
    /// </summary>
    private PlayerView view;

    /// <summary>
    /// 构造函数，注入了两个参数
    /// </summary>
    /// <param name="model">初始化赋值</param>
    /// <param name="view">初始化赋值</param>
    public PlayerContoller(PlayerModel model,PlayerView view)
    {
        this.model = model;
        this.view = view;
    }


    /// <summary>
    /// 控制设置玩家名字
    /// </summary>
    /// <param name="name"></param>
    public void SetPlayerName(string name)
    {
        if (string.IsNullOrEmpty(name))
        {
            Debug.Log("传入的参数为空");
            return;
        }
        
        
        //让数据层去改变数据
        model.SetName(name);
    }


    /// <summary>
    /// 获取玩家名字
    /// </summary>
    /// <returns></returns>
    public string GetPlayerName()
    {
        //返回数据中的名字
        return model.GetName();
    }


    /// <summary>
    /// 更新界面的结果
    /// </summary>
    public void UpdateView()
    {
        //显示界面的刷新结果
        view.Show(model.GetName());
    }

}
